﻿// DbProviderLib
// (c)2007 Mark Bulmahn. mBulmahn@web.de
// License: GPL 2.0
// Project: TestCaseGenerator. http://www.codeplex.com/TestCaseGenerator

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DbProviderLib
{
    /// <summary>
    /// A basic implementation for an MSSQL-Provider.
    /// </summary>
    public class MssqlProvider : DbProviderBase, IDbProvider
    {

        SqlConnection conn = null;
        public IDbConnection Connection
        {
            get
            {
                return conn;
            }
            set
            {
                conn = (SqlConnection)value;
            }
        }

        public MssqlProvider(string connStr)
        {
            this.conn = new SqlConnection(connStr);
            this.conn.Open();
        }

        public IDbCommand GetCommand(string cmdText)
        {
            SqlCommand cmd = new SqlCommand(cmdText, this.conn);
            return cmd;
        }

        public IDbDataAdapter GetAdapter(string cmdText)
        {
            SqlDataAdapter adapter = new SqlDataAdapter(cmdText, this.conn);
            SqlCommandBuilder bldr = new SqlCommandBuilder(adapter);
            return adapter;
        }

        public IDataReader GetReader(string cmdText)
        {
            SqlCommand cmd = new SqlCommand(cmdText, this.conn);
            SqlDataReader dr = cmd.ExecuteReader();
            return dr;
        }
    }
}
